home *** CD-ROM | disk | FTP | other *** search
- unit M2Main;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, TabNotBk, ExtCtrls, ComCtrls, PrevForm;
-
- type
- TOffsRec = record
- Offs: LongInt;
- Len: integer;
- end;
-
- TForm1 = class(TForm)
- OpenDialog1: TOpenDialog;
- Panel1: TPanel;
- Label2: TLabel;
- Label3: TLabel;
- Bevel1: TBevel;
- BitBtn2: TBitBtn;
- BitBtn1: TBitBtn;
- BitBtn3: TBitBtn;
- BitBtn4: TBitBtn;
- Label7: TLabel;
- ListBox2: TListBox;
- Memo1: TMemo;
- Label4: TLabel;
- ListBox1: TListBox;
- Label1: TLabel;
- BitBtn5: TBitBtn;
- procedure BitBtn2Click(Sender: TObject);
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn3Click(Sender: TObject);
- procedure BitBtn4Click(Sender: TObject);
- procedure BitBtn5Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.BitBtn2Click(Sender: TObject);
- begin
- if OpenDialog1.Execute then
- begin
- Label3.Caption := OpenDialog1.FileName;
- Memo1.Lines.LoadFromFile(Label3.Caption);
- end;
- end;
-
- procedure TForm1.BitBtn1Click(Sender: TObject);
- var
- Index: file of TOffsRec;
- i: LongInt;
- OffsRec: TOffsRec;
- begin
- { assign and create index file }
- AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
- Rewrite(Index);
- try
- for i := 0 to ListBox1.Items.Count-1 do
- begin
- OffsRec.Offs := StrToInt(ListBox1.Items[i]);
- OffsRec.Len := StrToInt(ListBox2.Items[i]);
- Write(Index, OffsRec); { write offset to index }
- end;
- finally
- { clean up }
- CloseFile(Index)
- end;
- end;
-
- procedure TForm1.BitBtn3Click(Sender: TObject);
- begin
- Listbox1.Items.Clear;
- Listbox2.Items.Clear;
- end;
-
- procedure TForm1.BitBtn4Click(Sender: TObject);
- var
- j: integer;
- F: TFileStream;
- Index: file of TOffsRec;
- S: string;
- OffsRec: TOffsRec;
- begin
- { open form file }
- F := TFileStream.Create(Label3.Caption, fmOpenWrite);
- try
- { assign and open index file }
- AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
- Reset(Index);
- try
- { iterate through index offsets }
- for j := 0 to FileSize(Index)-1 do
- begin
- Read(Index, OffsRec);
- { seek to offset }
- F.Seek(OffsRec.Offs, 0);
- S := Format('%*s', [OffsRec.Len, 'Offset: '+IntToStr(OffsRec.Offs)]);
- { write data to stream }
- F.Write(S[1], Length(S));
- end;
- finally
- CloseFile(Index);
- end;
- finally
- { clean up }
- F.Free;
- end;
- { show file in memo }
- CCForm.FileToShow := Label3.Caption;
- CCForm.Show;
- end;
-
- procedure TForm1.BitBtn5Click(Sender: TObject);
- begin
- ListBox1.Items.Add(IntToStr(Memo1.SelStart));
- ListBox2.Items.Add(IntToStr(Memo1.SelLength));
- end;
-
- end.
-